<template>
  <div class="show" @click="click">
    <van-icon name="delete-o" />
  </div>
</template>
<script>
import { Dialog } from 'vant'
export default {
  props: ['id'],
  mounted() {
    // click()
  },
  data() {
    return {
      show: false,
    }
  },
  components: {
    [Dialog.Component.name]: Dialog.Component,
  },
  methods: {
    reload() {
      const value = localStorage.getItem('data')
    },
    click() {
      this.show = true
      if (this.show) {
        Dialog.confirm({
          message: '你确定要删除此商品吗',
        })
          .then(() => {
            let b = 0
            const value = JSON.parse(localStorage.getItem('data'))
            value.forEach((element, index) => {
              if (element.goods_id == this.id) {
                b = index
              }
            })
            value.splice(b, 1)
            localStorage.setItem('data', JSON.stringify(value))
            location.reload()
          })
          .catch(() => {
            // on cancel
          })
      }
    },
  },
}
</script>
<style lang="less" scoped>
.show {
  display: flex;
  align-items: center;
  justify-content: center;
}
</style>
